<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>拉拉货物流有限公司</title>
		<meta name="keywords" content="拉拉货物流有限公司,汕头物流配送,汕头物流,汕头物流货运,汕头货运,全国货运,厦门物流配送,深圳物流配送,广州物流配送,物流配送,物流货运,货运配送" />
	    <meta name="description" content="拉拉货物流有限公司是一家承接全国各地门到门配送业务的专业第三方物流，为企业量身定做仓储、配送物流方案，针对大小客户配备专业项目小组进行专人专车对接。" />
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <link rel="stylesheet" href="css/amazeui.min.css" type="text/css" />
	    <link rel="stylesheet" href="css/style.css" type="text/css" />
	    <script type="text/javascript" src="js/jquery.min.js" ></script>
	    <script type="text/javascript" src="js/amazeui.min.js" ></script>
	</head>
	<style type="text/css">
		 #message{
		        width: 100%;
		        height: 500px;
		        border: 1px solid black;
		        background-color: darkgray;
				background: url(https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2480218763,1693274052&fm=26&gp=0.jpg);
		
		    }
		
		    #inputVal{
		        width: 50%;
		    }
		   
	</style>
	<body>
		<header data-am-widget="header" class="am-header am-header-default header-green1">
	      <div class="am-header-left am-header-nav ">
		        <a href="message.html" style="color: #fff;"><i class="am-icon-chevron-left"></i></a>
	        </div>
		  <h1 class="am-header-title" style="color: #fff;">聊天窗口</h1>
       </header>
       <div class="jl"></div>
       <div class="mess-con">
		  <div id="message">
		   	
		   </div>
       	  
       	  <div id="inputVal">
			 
			 	<input type="text" placeholder="请输入消息"  name="text" class="bt" />
		
			  
			  <button style="background-color:blue; color: white;height: 35px;" onclick="send()">发送</button>
       	  	
       	  </div>
		
       
       </div>
	</body>
	<script type="text/javascript">
		var user=JSON.parse(sessionStorage.getItem("user"))
		var url=JSON.parse(sessionStorage.getItem("url"))
		var newss=JSON.parse(sessionStorage.getItem("newss"))
		  var messageEl=document.getElementById("message");
		    var inputEl=document.getElementsByTagName("input")[0];
		    var websocket=null;
		    if('WebSocket' in window){
		        websocket=new WebSocket("ws:localhost:8081/websocket/"+user.userName);
		    }else {
		        alert("浏览器不支持");
		
		    }
		    websocket.onopen=function () {
		        console.log("webscoket已经连接成功");
		       
		
		    };
		    websocket.onclose=function () {
		        console.log("webscoket连接失败");
		        addMessage("webscoket连接失败");
		    };
		    websocket.onmessage=function (event) {
		        addMessage(event.data);
		    };
		    websocket.onerror=function () {
		        console.log("webscoket连接失败");
		        addMessage("webscoket连接失败");
		    };
		    function addMessage(message) {
		        messageEl.innerHTML+=message+"</br>";
		    }
		    
		    function send() {
		        websocket.send(user.userName+"："+inputEl.value);
		        messageEl.innerHTML+='<font size="5px" color="red">'+user.userName+"："+inputEl.value+'</font>'+"</br>";
				inputEl.value=''
				
		    }
			$.ajax({
				url:url+"/clientnews/upRead/?id="+newss.id,
				dataType:'json',
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				
			});

		
	</script>
</html>
